<?php
/*
 *   This file is part of poat.
 *
 *   poat is free software: you can redistribute it and/or modify
 *   it under the terms of the GNU General Public License as published by
 *   the Free Software Foundation, either version 3 of the License, or
 *   (at your option) any later version.
 *
 *   poat is distributed in the hope that it will be useful,
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *   GNU General Public License for more details.
 *
 *   You should have received a copy of the GNU General Public License
 *   along with poat.  If not, see <http://www.gnu.org/licenses/>.
 * 
 *   Copyright (c) 2008 Sergio Gabriel Teves <gabriel.sgt at gmail.com>
 */
// only a simple test
define('ROOT_PATH',dirname(__FILE__)."/");
include_once (ROOT_PATH."includes/ajaxsetup.php");

$objResponse = new xajaxResponse();
$objResponse->script("closeprogress()");
$objResponse->script("restoreTimeout()");

function checkNotice(&$objResponse,$message,$error) {
	if (isset($message)) {
		$objResponse->assign("messagenotice","innerHTML",'<p class="usermessage">'.$message.'</p>');	
	} else {
		$objResponse->assign("messagenotice","innerHTML","");
	}
	if (isset($error)) {
		$objResponse->assign("errornotice","innerHTML",'<p class="error">'.$error.'</p>');	
	} else {
		$objResponse->assign("errornotice","innerHTML","");
	}
	return $objResponse;
}

function loadHistory($id) {
	global $objResponse;
	
	include(ROOT_PATH."includes/history.php");
	$objResponse->contextAssign("result",$content);
	$objResponse->script("this.response('".$filename."');");
	checkNotice($objResponse, $message, $error);
	return $objResponse;
}

function sendMessage($data) {
	global $objResponse;
	
	include(ROOT_PATH."includes/mp.php");
	$objResponse->script("infoDialog('".APPLICATION_NAME."',\"".$content."\")");
	checkNotice($objResponse, $message, $error);

	return $objResponse;
}

function getHelp($data) {
	global $objResponse;
	
	include_once(ROOT_PATH."lang/lang_".$data['lang'].".inc");
	$objResponse->contextAssign("result",$LANG[$data['id']]);
	$objResponse->script("this.response('".$LANG['help']."');");
	checkNotice($objResponse, $message, $error);
		
	return $objResponse;
}

function updateFile($data) {
	global $objResponse;

	include(ROOT_PATH."includes/fileupdate.php");
	$objResponse->assign("filerow".$data['id'],"innerHTML",$content);
	checkNotice($objResponse, $message, $error);
		
	return $objResponse;


}

function rejectFile($rowid,$fileid,$comments) {
	global $objResponse;

	include(ROOT_PATH."includes/filecheckaction.php");
	$objResponse->assign("filerow".$rowid."-".$fileid,"style.display","none");
	checkNotice($objResponse, $message, $error);
	return $objResponse;

}

function actionPackage($rowid,$op) {
	global $objResponse;

	include(ROOT_PATH."includes/filecheckaction.php");
	
	if ($op == "reject") {
		$objResponse->assign("filetable".$rowid,"style.display","none");	
	} else {
		$objResponse->assign("filetable".$rowid,"innerHTML",$content);
	}
	
	checkNotice($objResponse, $message, $error);
	return $objResponse;

}

function workload($teamid) {
	global $objResponse;
	
	include(ROOT_PATH."includes/workload.php");
	$objResponse->contextAssign("result",$content);
	$objResponse->script("this.response('".$LANG['workload']."');");
	checkNotice($objResponse, $message, $error);
	return $objResponse;
}

function listMyFiles() {
	global $objResponse;
	
	include(ROOT_PATH."includes/listMyFiles.php");
	$objResponse->contextAssign("result",$content);
	$objResponse->script("this.response(\"".$LANG['myfiles']."\");");
	checkNotice($objResponse, $message, $error);
	return $objResponse;
}

function getUpdateFileForm($fileid) {
	global $objResponse;
	include(ROOT_PATH."includes/updatefileform.php");
	$objResponse->contextAssign("result",$content);
	$objResponse->script("this.response('".$filename."');");
	checkNotice($objResponse, $message, $error);
	return $objResponse;
}

function updateUser($data) {
	global $objResponse;
	
	include(ROOT_PATH."includes/userlistreload.php");
	
	if ($updatecontent) $objResponse->assign("user_list_content","innerHTML",$content);
	checkNotice($objResponse, $message, $error);

	return $objResponse;
}

function sendMeMyFiles() {
	global $objResponse;

	include(ROOT_PATH."includes/sendmemyfiles.php");
	$objResponse->script("infoDialog('".APPLICATION_NAME."','".$content."')");
	checkNotice($objResponse, $message, $error);
	return $objResponse;
}

function getFileList($data) {
	global $objResponse;

	include(ROOT_PATH."includes/filelistreload.php");
	$objResponse->assign("filelist_content","innerHTML",$content);
	$objResponse->assign("totaluntranslated","innerHTML",$tuns);
	$objResponse->assign("totalfuzzy","innerHTML",$tfuz);
	$objResponse->assign("totalstrings","innerHTML",$tfuz+$tuns+$ttran);
	$objResponse->assign("listpager_content","innerHTML",$pagercontent);
	checkNotice($objResponse, $message, $error);
	return $objResponse;
}

function browseTo($data) {
	global $objResponse;
	$browsing=true;
	include(ROOT_PATH."includes/ajaxprocessor.php");
	$objResponse->assign("dynamic_content_body","innerHTML",$content);

	if (isset($applicationmenu)) {
		$objResponse->assign("application_menu","innerHTML",$applicationmenu);
	}
	if (isset($applicationform)) {
		$objResponse->script($function."(\"".$applicationform."\")");
		$objResponse->assign("application_menu","innerHTML",$applicationmenu);
	}

	checkNotice($objResponse, $message, $error);	
	return $objResponse;
}

function glossaryAction($data) {
	global $objResponse;
	$data['action']="glossary";
	include(ROOT_PATH."includes/ajaxprocessor.php");
	
	if ($data['window']=="true") {
		if ($content!="") {
			$objResponse->contextAssign("result",$content);
			$objResponse->script("this.response('');");
		}
	} else {
		if ($updatecontent !== false) {
			$objResponse->assign("glossary_content","innerHTML",$content);
		}
	}
	checkNotice($objResponse, $message, $error);	
	return $objResponse;		

}

function removeFile($id,$prj) {
	global $objResponse;
	$op="remove";
	include(ROOT_PATH."includes/filesaction.php");
	$objResponse->assign("filerow".$id,"innerHTML",$content);
	checkNotice($objResponse, $message, $error);	
	return $objResponse;		
}

function addFile($data) {
	global $objResponse;
	$op="add";
	include(ROOT_PATH."includes/filesaction.php");
	checkNotice($objResponse, $message, $error);	
	return $objResponse;		
}

$xajax->processRequest();

?>
